    const local=require("../../../data/local");
    const app=getApp();
    Page({
        data:{
            isPlay:false,
            Collected:false,
            Shared:false
        },
      onLoad:function(options){
          var self=this;
          var id=options.id;
          var data=local.postList[options.id];
          this.setData({
              data,
              postId:id,
              music:local.postList[options.id].music,
          }),
          this.onMusic();
          if(app.globalData.g_isPlay){
              this.setData({
                  isPlay:true
              });
          };
          let allCollected=wx.getStorageSync('allCollected');
          if(allCollected){
              let storageCollected=allCollected[id];
              this.setData({
                  Collected:storageCollected
              })
          }else{
              let allCollected={
              };
              allCollected[id]=false;
              wx.setStorageSync('allCollected', allCollected);
          };
          let allShared=wx.getStorageSync('allShared');
          if(allShared){
              let storageShared=allShared[id];
              this.setData({
                  Shared:storageShared
              })
          }else{
              let allShared={
              };
              allShared[id]=false;
              wx.setStorageSync('allShared', allShared);
          }
        },
          onMusic(){
            var self=this;
             wx.onBackgroundAudioPlay((result)=>{
              self.setData({
                  isPlay:true
              });
              app.globalData.g_isPlay=true;
              app.globalData.g_currentId=self.data.postId;
          });
          wx.onBackgroundAudioPause((result)=>{
              self.setData({
                  isPlay:false,
              });
              app.globalData.g_isPlay=false;
              app.globalData.g_currentId=null;
          });
          wx.onBackgroundAudioStop((result)=>{
              self.setData({
                  isPlay:false
              });
          });
        },
      playMusic(){
            var self=this;
          if(this.data.isPlay){
              wx.stopBackgroundAudio();
              this.setData({
                  isPlay:false,
              })
          }else{
          wx.playBackgroundAudio({
              dataUrl: self.data.music.url,
              title: self.data.music.title,
              coverImgUrl: self.data.music.coverImgUrl,
          });
          this.setData({
              isPlay:true
          })
        }
      },
      onCollect(){
          var allCollected=wx.getStorageSync('allCollected');
          var storageCollected=allCollected[this.data.postId];
          storageCollected=!storageCollected;
          allCollected[this.data.postId]=storageCollected;
          wx.setStorageSync("allCollected", allCollected);
          this.setData({
              Collected:storageCollected
          })
      },
      onShare(){
        //   this.setData({
        //       Shared:!this.data.shared
        //   })
          wx.showActionSheet({
              itemList: ["分享到微信","分享到微博","分享到qq空间"],
              itemColor: '#aaa',
              success:res=>{
                  console.log(res.tapIndex);
                  this.setData({
                      Shared:true
                  })
              },
              fail:err=>{
                  this.setData({
                      Shared:false
                  })
              }
          });
      }
     })